<?php

require_once FILE_CLASS_SEARCH;

if (isset($_POST['submit'])){
    
    $search = new Search(($_POST['term']), ($_POST['type'])); 
    
//                
}
?>
     <div id="header">
    <div id="logo"></div>
    <div id="headertext">Zoekpagina</div>
</div>
<div id="content2">
    <div id="contentbg">
        <div id="contentblock1">
            <div id="contentblock1text">
<form method="post">
    Zoeken: <input type="text" name="term" name="zoeken" class="zoeken"  /><a href="#" class="tooltip"><img src="images/tooltip_icon.png"><span> Voer hier de zoekopdracht in. Dit is een verplicht veld.</span></a>
    <select name ="type">
        <option value="Person">Persoon</option>
        <option value="WPI">Werplekinspectie</option>
        <option value="Bedrijfsonderdeel">Bedrijfsonderdeel</option>
    </select>
    <input type="submit" style="width: 60px; margin-right: 5px;" name="submit" value="zoeken" id="koppelknoppen" class="zoekbutton" />
    
</form>
                   </div>               
            </div>
            <?php
              if (isset($_POST['submit'])) { 
            ?>
        <div id="contentblock1">
            Zoekresultaten:<br/><br/>
             <?php
             $result = FALSE;
             $test = $search->Search();
             if(isset($_POST['submit'])){
             if(empty($test)){
                 echo "<span style='color: red;'>Kan zoekresultaat niet weergeven</span>";

             }else{
                foreach ($search->Search() as $key => $array) {
                  
                    switch ($search->getType()) {

                        case "Person":
                            if (empty($array['registratienummer'])) {
                                $result = FALSE;
                            } else {
                                print "<div id='overzichttable'>";
                                print "<table>";
                                print "<tr> 
                                        <td style ='width:120px;'>". $array['registratienummer'] . "</td> 
                                        <td style ='width:120px';>" . $array['voornaam']. "". $array['achternaam'] ."</td> 
                                        <td style ='width:240px';>" .  $array['functie'] .  "</td> 
                                        <td style ='width:150px';>" .  $array['email'] .  "</td>
                                        <td style ='width:150px';>" .  $array['tel_mobiel'] .  "</td> 
                                       </tr>";
                                print "</table>";
                                print "</div>";
                                $result = TRUE;
                            }
                            break;

                        case "WPI":
                            if (empty($array['id'])) {
                                $result = FALSE;
                            } else {
                                print "<div id='overzichttable'>";
                                print "<table>";
                                 print "<tr>
                                        <td style ='width: 120px;'>". $array['id'] . "</td> 
                                        <td style ='width:120px';>" . $array['laag_id'] . "</td> 
                                        <td style ='width:240px';>" .  $array['beschrijving'] .  "</td> 
                                        <td style ='width:150px';>" .  $array['leidinggevende_id'] .  "</td> 
                                        <td style ='width:150px';>" .  $array['locatie'] .  "</td> 
                                       </tr>";  
                                print "</table>";
                                print "</div>";
                                $result = TRUE;
                            }
                            break;

                        case "Bedrijfsonderdeel":
                            if (empty($array['id'])) {
                                $result = FALSE;
                            } else {
                                print "<div id='overzichttable'>";
                                print "<table>";
                                print "<tr>
                                        <td style ='width: 120px;'>". $array['id'] . "</td> 
                                        <td style ='width:120px';>" . $array['laag_id'] . "</td> 
                                        <td style ='width:240px';>" .  $array['beschrijving'] .  "</td> 
                                        <td style ='width:150px';>" .  $array['leidinggevende_id'] .  "</td> 
                                        <td style ='width:150px';>" .  $array['locatie'] .  "</td> 
                                       </tr>";  
                                print "</table>";
                                print "</div>";
                                $result = TRUE;
                            }
                            break;
                    }
                }
                if ($result == FALSE) {
                    echo "<span style='color: red;'>Kan zoekresultaat niet weergeven</span>";
                }
             }
             }
          }else{
              echo "";
          }
            ?>
            
        </div>
       <a id="koppelknoppen" style="float:left;" href="index.php">
                Terug
            </a>
        </div> 
    </div>        
</div>

               